import { container } from "tsyringe"
import { App } from "./app"
import { FloatyWindow } from "../autox/floatWindow"

export class KwaiApp extends App {
    constructor() {
        super(KwaiApp.packageName, '快手')
    }
    render(): void {
        const floatWindow = container.resolve(FloatyWindow)
        floatWindow.render(`<frame id="main" w="*" h="*" bg="#000000" alpha="0">
        <vertical w="*" h="*">
            <horizontal padding="15 5 15 5">
                <text w="*" padding="15 5 15 5" bg="#130B2E" h="auto" id="toast" textSize="16" gravity="center" text="" textColor="#D12E2E"/>
            </horizontal>
            <horizontal padding="15 5 15 5">
                <horizontal layout_weight="1">
                    <text w="auto" textSize="12" gravity="left" text="当前应用：" textColor="#E2E1CF"/>
                    <text w="*" id="currentApp" textSize="14" gravity="left" text="-" textColor="#F2F2F2"/>
                </horizontal>
                <horizontal layout_weight="1">
                    <text w="auto" textSize="12" gravity="left" text="当前任务：" textColor="#E2E1CF"/>
                    <text w="*" id="currentTask" textSize="14" gravity="left" text="-" textColor="#F2F2F2"/>
                </horizontal>
            </horizontal>
            <horizontal padding="15 5 15 5">
                <text w="auto" textSize="12" gravity="left" text="执行结果：" textColor="#F2F2F2"/>
                <text w="*" id="currentResult" textSize="14" gravity="left" text="-" textColor="#E2E1CF"/>
            </horizontal>
            <horizontal padding="15 5 15 5">
                <horizontal layout_weight="1">
                    <text w="auto" textSize="12" gravity="left" text="快手：" textColor="#F2F2F2"/>
                    <text w="*" id="kwaiCurrentMoney" textSize="14" gravity="left" text="-" textColor="#E2E1CF"/>
                </horizontal>
                <horizontal layout_weight="1">
                    <text w="auto" textSize="12" gravity="left" text="分配：" textColor="#F2F2F2"/>
                    <text w="*" id="kwaiTodayCount" textSize="14" gravity="left" text="-" textColor="#E2E1CF"/>
                </horizontal>
                <horizontal layout_weight="1">
                    <text w="auto" textSize="12" gravity="left" text="快币：" textColor="#F2F2F2"/>
                    <text w="*" id="kwaiTodayMoney" textSize="14" gravity="left" text="-" textColor="#E2E1CF"/>
                </horizontal>
            </horizontal>
            <horizontal padding="15 5 15 5">
                <horizontal layout_weight="1">
                    <text w="auto" textSize="12" gravity="left" text="极速：" textColor="#F2F2F2"/>
                    <text w="*" id="nebulaCurrentMoney" textSize="14" gravity="left" text="-" textColor="#E2E1CF"/>
                </horizontal>
                <horizontal layout_weight="1">
                    <text w="auto" textSize="12" gravity="left" text="分配：" textColor="#F2F2F2"/>
                    <text w="*" id="nebulaTodayCount" textSize="14" gravity="left" text="-" textColor="#E2E1CF"/>
                </horizontal>
                <horizontal layout_weight="1">
                    <text w="auto" textSize="12" gravity="left" text="快币：" textColor="#F2F2F2"/>
                    <text w="*" id="nebulaTodayMoney" textSize="14" gravity="left" text="-" textColor="#E2E1CF"/>
                </horizontal>
            </horizontal>
            <horizontal padding="15 5 15 5">
                <text w="*" id="tip" textSize="12" gravity="center" text="-" textColor="#f29a8c"/>
            </horizontal>
            <horizontal h="50"></horizontal>
        </vertical>
    </frame>`)
        let state = {}
        const updateUi = (state: any) => {
            ui.run(() => {
                Object.keys(state).map(key => {
                    const val = state[key]
                    if (val) {
                        floatWindow.window[key].setText(state[key])
                    } else {
                        log(`${key}:${val}`)
                    }
                })
            })
        }
        floatWindow.on('UPDATE_FLOAT_WINDOW_STATE_CHANGE', (val: any) => {
            state = {
                currentTask: '抢包',
                ...state,
                ...val,
            };
            updateUi(state)
        });
    }
    static packageName: string = `com.smile.gifmaker`
    static is(app: App) {
        return app.packageName === KwaiApp.packageName
    }
}